"""
功能描述 ：
编写人 ：
编写日期 ：
实现逻辑 ：
    1- ......
        1.1- ......
    2- ......
        2.1- ......
"""
# #了解异
# open('test.txt', 'r')
# #异常的写法
# try:
#     open('test.txt', 'r')
# except:
#     open('test.txt', 'w')
#
# #捕获指定异常
# try:
#     print(1/0)
# except NameError:
#     print("有错误")
#
# #捕获多个指定异常
#
# try:
#     print(1/0)
# except (NameError,ZeroDivisionError):
#     print('错误')
#
# #捕获异常描述信息
# try:
#     print(num )
# except (NameError,ZeroDivisionError) as result:
#     print(result)
#
# #捕获所有异常
# try:
#     print(num)
# except Exception as result:
#     print(result)
#
# #异常的else
# try:
#  print(1)
# except Exception as result:
#  print(result)
# else:
#  print('我是else，是没有异常的时候执⾏的代码')
# #异常finally
# try:
#  f = open('test.txt', 'r')
# except Exception as result:
#  f = open('test.txt', 'w')
# else:
#  print('没有异常，真开⼼')
# finally:
#  f.close()
# #异常传递
# import time
# try:
#     f = open('test.txt')
#     try:
#         while True:
#             content = f.readline()
#         if len(content) == 0:
#             break
#         time.sleep(2)
#         print(content)
#         except
#         # 如果在读取⽂件的过程中，产⽣了异常，那么就会捕获到
#         # ⽐如 按下了 ctrl+c
#         print('意外终⽌了读取数据')
#         finally:
#         f.close()
#         print('关闭⽂件')
#     except:
#         print("没有这个⽂件")
#自定义异常

class ShortInputError(Exception):
    def __init__(self,length,min_len):
        self.length = length
        self.min_len = min_len
        #设置抛出异常的描述信息
    def __str__(self):
        return f'你输入的长度{self.length},不能少于{self.min_len}个字符'
    def main(self):
        try:
            con = input('请输入密码')
            if len(con ) < 3:
                raise ShortInputError(len(con),3)
        except Exception as result:
            print(result)
        else:
            print('密码已经输入完成')
if __name__ == '__main__':
    ShortInputError
 #带参数的__init__() __init__()
# class xiyiji():
#     def __init__(self,width,height):
#         self.width = width
#         self.height = height
#     def print_info(self):
#         print(f'洗⾐机的宽度是{self.width}')
#         print(f'洗⾐机的⾼度是{self.height}')
# haier2 = xiyiji(100,105)
# haier2.print_info()
#烤地瓜案例
class SweetPotato():
    def __init__(self):
        self.cook_time = 0
        self.cook_static = '生的'
        self.condiments = []
    def cook(self,time):
        self.cook_time += time
        if 0 <= self.cook_time <= 3:
            self.cook_static = '生的'
        elif 3 <= self.cook_time <= 6:
            self.cook_static = '半熟'
        elif 6 <= self.cook_time <= 9:
            self.cook_static = '全熟'
        elif self.cook_time >= 9:
            self.cook_static= '烤糊了'
    def __str__(self):
        return f'这个地⽠烤了{self.cook_time}分钟, 状态是{self.cook_static}'
    def add_condiments(self,condiment):
        self.add_condiment.append(condiments)
    def _str_(self):
        return f'这个地⽠烤了{self.cook_time}分钟, 状态是{self.cook_static}, 添加的调料有{self.condiments}'
digua1 = SweetPotato()
print(digua1)
digua1.cook(2)
digua1.add_condiments('酱油')
print(digua1)
digua1.cook(2)
digua1.add_condiments('辣椒⾯⼉')
print(digua1)
digua1.cook(2)
print(digua1)
digua1.cook(2)
print(digua1)
